package com.tiny.mirror.service.product.interfaces.controller;

import com.api.tiny.mirror.service.product.AbilityApiService;
import com.api.tiny.mirror.service.product.request.CreateAbilityRequest;
import com.api.tiny.mirror.service.product.request.PageAbilityRequest;
import com.api.tiny.mirror.service.product.request.UpdateAbilityRequest;
import com.api.tiny.mirror.service.product.response.AbilityVO;
import com.tiny.mirror.basic.log.annotation.LogBody;
import com.tiny.mirror.basic.web.dto.response.BasePageResponse;
import com.tiny.mirror.basic.web.dto.response.BaseResponse;
import com.tiny.mirror.service.product.application.command.AbilityCmdService;
import com.tiny.mirror.service.product.application.query.AbilityQryService;
import java.util.Arrays;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: liujsh
 * @Description:
 * @Date: Create in 2023/9/25
 */
@RestController
public class AbilityController implements AbilityApiService {

  @Resource
  private AbilityQryService abilityQryService;
  @Resource
  private AbilityCmdService abilityCmdService;

  @LogBody
  @Override
  public BasePageResponse<AbilityVO> page(@RequestBody @Validated PageAbilityRequest request) {
    return abilityQryService.page(request);
  }

  @Override
  public BaseResponse<AbilityVO> getInfo(@PathVariable(value = "id") Long id) {
    return BaseResponse.success(abilityQryService.getInfo(id));
  }

  @LogBody
  @Override
  public BaseResponse<Long> create(@RequestBody @Validated CreateAbilityRequest request) {
    return BaseResponse.success(abilityCmdService.create(request));
  }

  @LogBody
  @Override
  public BaseResponse<Void> update(@RequestBody @Validated UpdateAbilityRequest request) {
    abilityCmdService.update(request);
    return BaseResponse.success();
  }

  @Override
  public BaseResponse<Integer> delete(@PathVariable(value = "ids") Long[] ids) {
    abilityCmdService.delete(Arrays.asList(ids));
    return BaseResponse.success();
  }
}
